package com.kk.permission.huawei.bnd_al00_26;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.core.app.NotificationCompat;

import com.kk.permission.GuideConst;
import com.kk.permission.handler.ConfigHandler;
import com.kk.permission.huawei.HuaweiPermissionAccessbilityHandlerBase;
import com.kk.permission.huawei.HuaweiPermissionStrategyBase;
import com.kk.permission.utils.OSUtil;
import com.kk.permission.utils.Permission;
import com.kk.permission.utils.callershow.CallerShowUtils;

import java.util.ArrayList;

public class HuaweiBNDAL00SDK26PermissionGuideStrategy extends HuaweiPermissionStrategyBase {
    private static final String TAG = "HuaweiPermissionGuide";

    public HuaweiBNDAL00SDK26PermissionGuideStrategy(Context context) {
        super(context);
    }

    protected void actionReadCalllog() {
        super.actionReadCalllog();
        actionTrustApplicationPermission(true);
    }

    protected void actionReadContact() {
        super.actionReadContact();
        actionTrustApplicationPermission(true);
    }

    protected void actionTrustApplicationPermission(boolean z) {
        super.actionTrustApplicationPermission(z);
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
            startIntentActivities(intent, GuideConst.TRUST_APPLICATION_PERMISSION, this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    protected void actionAutoBootPermission()
    {
        super.actionAutoBootPermission();
        try
        {
            Intent localIntent = new Intent();
            localIntent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
            startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);
        }
        catch (Exception localException1)
        {
            try
            {
                Intent localIntent = new Intent();
                localIntent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity");
                startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);

            }
            catch (Exception localException2)
            {
            }
        }
    }


    protected void actionToastPermission() {
        super.actionToastPermission();
        try {
            Intent intent = new Intent();
            intent.setClassName("com.android.settings", GuideConst.HUAWEI_SYSTEM_DIALING_PERMISSION_ACTIVTIY_NAME_V6);
            boolean startIntentActivities = startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
//            if (!this.mAutoGuide && startIntentActivities) {
//                intent = new Intent(this.mContext, OuterPermissionActivity.class);
//                intent.putExtra(OuterPermissionActivity.VIEWSTUB_ID, R.layout.general_permission_guide_mask);
//                intent.putExtra(OuterPermissionActivity.GUIDEPIC_ID, WrapViewGenerator.getInstance().getViewByResId(R.drawable.samsung7_boot_three));
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTONE, StringUtils.getFullStringWithAppName(R.string.miui_permission_guide_template_one));
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTTWO, this.mContext.getString(R.string.permission_toast_vivo_4_0));
//                this.mContext.startActivity(intent);
//            }
        } catch (ActivityNotFoundException unused) {
        } catch (Throwable e) {
        }
    }

    protected void actionBackgroundPermisssion() {
        super.actionBackgroundPermisssion();
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_BACKGROUND_PROTECT_PERMISSION_ACTIVITY_NAME);
            startIntentActivities(intent, GuideConst.BACKGROUND_PROTECT_PERMISSION, this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    protected void actionWhiteListPermisssion() {
        super.actionWhiteListPermisssion();
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.mainscreen.MainScreenActivity");
            startIntentActivities(intent, "white_list", this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    protected void actionPermissionDeny(int i) {
        if (3 == i || 1 == i || 2 == i) {
            actionTrustApplicationPermission(true);
            return;
        }
        throw new IllegalArgumentException();
    }

    protected void actionCallogOrContactPermission() {
        super.actionCallogOrContactPermission();
        actionTrustApplicationPermission(true);
    }

    protected void actionDozePermission() {
        super.actionDozePermission();
        try {
            startIntentActivities(new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"), GuideConst.DOZE_PERMISSION, this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    public ArrayList<String> getPermissionList() {
        ArrayList<String> arrayList = new ArrayList();
        for (Permission permission : ConfigHandler.getInstance().getPermissionList()) {
            switch (permission) {
                case TOAST:
                    arrayList.add(GuideConst.TOAST_PERMISSION);
                    break;
                case CALL_RINGTONE:
//                    if(!PermissionListUtil.isSupportModifyWriteSettingPermission())
                        arrayList.add(GuideConst.CALL_RINGTONE_PERMISSION);
                    break;
                case DIAL_NOTI:
//                    if(!PermissionListUtil.notificationListenerEnable())
                        arrayList.add(GuideConst.DIAL_NOTI_PERMISSION);
                    break;
                case AUTO_BOOT:
                    if (!OSUtil.isHuaweiCLT_AL01_SDK28()) {
                        arrayList.add(GuideConst.AUTOBOOT_PERMISSION);
                        break;
                    }
                    break;
                case SHORTCUT:
                    arrayList.add(GuideConst.INSTALL_SHORT_CUT);
                    break;
                case BACKGROUND_PROTECT:
                    break;
                case SYSTEM_DIALING:
                    arrayList.add(GuideConst.SYSTEM_DIALING_PERMISSION);
                    break;
                default:
                    break;
            }
        }
        return arrayList;
    }

    protected void actionDialNotiPermission() {
        super.actionDialNotiPermission();
        try {
            boolean startIntentActivities = startIntentActivities(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"), GuideConst.DIAL_NOTI_PERMISSION, this.mAutoGuide);
//            if (!this.mAutoGuide && startIntentActivities) {
//                Intent intent = new Intent(this.mContext, OuterPermissionActivity.class);
//                intent.putExtra(OuterPermissionActivity.VIEWSTUB_ID, R.layout.general_permission_guide_mask);
//                intent.putExtra(OuterPermissionActivity.GUIDEPIC_ID, WrapViewGenerator.getInstance().getViewByResId(R.drawable.samsung7_boot_three));
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTONE, StringUtils.getFullStringWithAppName(R.string.miui_permission_guide_template_one));
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTTWO, this.mContext.getString(R.string.permission_noti_vivo_4_0));
//                this.mContext.startActivity(intent);
//            }
        } catch (ActivityNotFoundException e) {

        }
    }

    public HuaweiPermissionAccessbilityHandlerBase getHandlerBase() {
        return new HuaweiBNDAL00SDK26PermissionAccessbilityHandler(this.mContext);
    }

    protected void actionCallRingtonePermission() {
        super.actionCallRingtonePermission();
        try {
            CallerShowUtils.jumpToSysMidifySettingActivity(this.mContext);
//            if (!this.mAutoGuide) {
//                Intent intent = new Intent(this.mContext, OuterPermissionActivity.class);
//                intent.putExtra(OuterPermissionActivity.VIEWSTUB_ID, R.layout.general_permission_guide_mask);
//                intent.putExtra(OuterPermissionActivity.GUIDEPIC_ID, WrapViewGenerator.getInstance().getViewByResId(R.drawable.permission_system_vivo_4_0));
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTONE, "");
//                intent.putExtra(OuterPermissionActivity.GUIDE_HINTTWO, this.mContext.getString(R.string.permission_call_vivo_4_0));
//                this.mContext.startActivity(intent);
//            }
        } catch (Exception unused) {
        }
    }

    protected void actionInstallShortCut() {
        super.actionInstallShortCut();
        if (!this.mAutoGuide) {
//            Intent intent = new Intent(this.mContext, OuterPermissionActivity.class);
//            intent.putExtra(OuterPermissionActivity.VIEWSTUB_ID, R.layout.huawei_app_permission_guide_8);
//            intent.putExtra(OuterPermissionActivity.GUIDEPIC_ID, WrapViewGenerator.getInstance().getViewByResId(R.drawable.permission_system_vivo_4_0));
//            intent.putExtra(OuterPermissionActivity.GUIDE_HINTONE, "");
//            intent.putExtra(OuterPermissionActivity.GUIDE_HINTTWO, this.mContext.getString(R.string.permission_call_vivo_4_0));
//            this.mContext.startActivity(intent);
        }
    }

    protected void actionSystemDialingPermission() {
        super.actionSystemDialingPermission();
        Log.e("zhaoyanjun:han", NotificationCompat.CATEGORY_SYSTEM);
        Intent intent = new Intent();
        intent.setClassName("com.android.settings", GuideConst.HUAWEI_SYSTEM_DIALING_PERMISSION_ACTIVTIY_NAME_V9);
        startIntentActivities(intent, GuideConst.SYSTEM_DIALING_PERMISSION, this.mAutoGuide);
    }
}
